// pages/mine/mine.js
const app = getApp()
Page({

  data: {
    userName: "未知用户",
    avatarUrl: "",
    wxname :'请文明一点',
    sex : '男',
    is_bus:'',
    is_businfo:'',
    verify:'',
    list: [
      {
        src: "../../img/a_52_07.png",
        name: "资料编辑"
      },
      {
        src: "../../img/a_53_07.png",
        name: "我的评论"
      },
      {
        src: "../../img/a_54_07.png",
        name: " 我的订单"
      },
      {
        src: "../../img/a_55_07.png",
        name: "我的返现"
      },
      {
        src: "../../img/a_56_07.png",
        name: "消息通知"
      },
      {
        src: "../../img/a_57_07.png",
        name: "   我的收藏"
      },
      {
        src: "../../img/a_58_07.png",
        name: "申请入驻"
      },
      {
        src: "../../img/a_59_07.png",
        name: "声明公告"
      },
      {
        src: "../../img/a_61_03.png",
        name: "申请查看"
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    that.setData(wx.getStorageSync('userinfo'));
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  mall: function () {
    wx.redirectTo({
      url: "../mall/mall"
    })
  },
  issue: function () {
    wx.navigateTo({
      url: "../issue/issue"
    })
  },
  car: function () {
    wx.redirectTo({
      url: "../car/car"
    })
  },
  index: function () {
    wx.redirectTo({
      url: "../index/index"
    })
  },
  myads: function () {
    wx.navigateTo({
      url: "../myads/myads"
    })
  },
  myqx: function () {
    var that = this
    if (that.data.is_bus == 0){
      wx.showToast({
        title: '你还不是商家',
      },1000)
    } else if(that.data.is_bus == 1){
      wx.navigateTo({
        url: "../qxmy/qxmy"
      })
    }
  },
  ckqx:function(){
    wx.navigateTo({
      url: "../ckqx/ckqx"
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    that.setData({
      userName: app.data.userName ||"未知用户"
    })
    that.setData({
      avatarUrl: app.data.avatarUrl ||"../../img/a_50_03.png"
    })
    var uid = wx.getStorageSync('uid')
    wx.request({
      url: app.url + '/business/is_bus',
      data: {
        uid: uid
      },
      method: 'GET',
      success: function (res) {
        if (!res.data.data || res.data.data.verify==-1) {
          that.setData({
            is_bus:0,
            is_businfo:"申请入驻"
          })
        } else {
          that.setData({
            is_bus: 1,
            is_businfo: "编辑入驻信息",
            verify: res.data.data.verify
          })
          wx.setStorageSync('bid', res.data.data.bid)
        }
      },
    })
    wx.request({
      url: app.url + '/user/userinfo',
      data: {
        uid: uid
      },
      method: 'GET',
      success: function (res) {
        if (!res.data.data.username) {
          wx.showModal({
            title: '个人信息',
            content: '请先完善个人信息，便于提供售后理赔',
            success:function(res){
              if(res.confirm){
                wx.navigateTo({
                  url: '../editinfo/editinfo',
                })
              }else if(res.cancel){
                console.log('用户点击取消')
              }
            }
          })
        }
      },
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
   /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  // 八块点击跳转
  chunk1:function(){
    wx.navigateTo({
      url: '../editinfo/editinfo',
    })
  },
  chunk2: function () {
    wx.navigateTo({
      url: '../report/report',
    })
  },
  chunk3: function () {
    wx.navigateTo({
      url: '../order/order',
    })
  },
  chunk4: function () {
    wx.navigateTo({
      url: '../cashback/cashback',
    })
  },
  chunk5: function () {
    wx.navigateTo({
      url: '../notify/notify',
    })
  },
  chunk6: function () {
    wx.navigateTo({
      url: '../collect/collect',
    })
  },
  chunk7: function () {
    var that = this
    if (that.data.is_bus == 0){
      wx.navigateTo({
        url: '../enter/enter',
      })
    } else if (that.data.is_bus == 1){
      if (that.data.verify == 0){
        wx.showToast({
          title: '正在审核中',
        })
        return false
      }else if (that.data.verify == 1) {
        wx.navigateTo({
          url: '../enter_edit/enter_edit?bid='+wx.getStorageSync('bid'),
        })
      }  
    }
  },
  chunk8: function () {
    wx.navigateTo({
      url: '../state/state',
    })
  }
})